package com.septagon.wildtunnel.model;

import java.io.*;
import java.net.*;

import org.apache.http.*;
import org.apache.http.client.*;
import org.apache.http.client.methods.*;
import org.apache.http.impl.client.*;
import org.apache.http.params.CoreProtocolPNames;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.apache.http.util.EntityUtils;

import android.graphics.*;
import android.os.*;

public class HttpClient {
	
	public HttpClient(){
		this.userAgent = "Monazilla/1.00(VIPBrowser/1.00)";
		this.defaultEncoding = "Shift-JIS";
	}
	
	private String userAgent;
	private String defaultEncoding;

	public String getUserAgent(){
		return this.userAgent;
	}
	
	public void setUserAgent(String agent){
		this.userAgent = agent;
	}
	
	
	
	public String httpGetString(String url){
		try
		{
			HttpGet method = new HttpGet( url );

		    DefaultHttpClient client = new DefaultHttpClient();

		    method.setHeader("User-Agent", this.userAgent);
		      
		    HttpResponse response = client.execute( method );
		    int status = response.getStatusLine().getStatusCode();
		    if ( status != HttpStatus.SC_OK )
		    	throw new Exception();
		    
		    InputStream is = response.getEntity().getContent();
		    BufferedReader reader = new BufferedReader(new InputStreamReader(is,this.defaultEncoding));
		    StringBuffer buf = new StringBuffer();
	    	String str;
	    	
	    	while ((str = reader.readLine()) != null) {
	            buf.append(str);
	            buf.append("\n");
	    	}
	    	return buf.toString();
		}
		catch ( Exception e )
		{
			return null;
		}
	}

	public String getDefaultEncoding() {
		return defaultEncoding;
	}

	public void setDefaultEncoding(String defaultEncoding) {
		this.defaultEncoding = defaultEncoding;
	}
	
}
